<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
    <title>登陆</title>
</head>

<body>
<div>
    <div id="mesg"></div>
    用户名:<input id="userName" ><br>
    密  码:<input id="password" type="password"><br>
    <button type="button" onclick="login()">登录</button>
</div>
</body>

<script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
    function login(){
        var userName = $("#userName").val();
        if(userName==undefined||userName.trim()==""){
            $("#mesg").text("对不起,用户名不能为空");
            return;
        }

        var password = $("#password").val();
        if(password==undefined||password.trim()==""){
            $("#mesg").text("对不起,密码不能为空");
            return;
        }

        $.ajax({
            url:"login",
            type:"post",
            data:{"userName":userName,"password":password},
            success:function(obj){
                var data=JSON.parse(obj);
                console.info(data)
                if(data.code==0){
                    $("#mesg").text(data.mes);

                }else{
                    location.href="getInfo"
                }
            }

        })
    }

</script>
</html>
